package com.uniontech.curd.service.impl;

import com.uniontech.curd.dao.CURDDao;
import com.uniontech.curd.entity.Users;
import com.uniontech.curd.entity.http.Pager;
import com.uniontech.curd.service.CURDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CURDServiceImpl implements CURDService {

    @Autowired
    private CURDDao curdDao;

    @Override
    @Transactional
    public boolean addUsers(Users users){
        return curdDao.add(users);
    }

    @Override
    @Transactional
    public boolean updateUsers(Users users){
        return curdDao.update(users);
    }

    @Override
    public boolean deleteUsers(Users users){
        return curdDao.delete(users);
    }


    @Override
    public Pager<Users> page(String searchContent){
        int count = curdDao.count(searchContent);
        Pager<Users> pager = new Pager<>();
        if(count > 0){
            List<Users> usersList = curdDao.list(searchContent);
            pager.setData(usersList);
        }
        return pager;
    }
}
